﻿using System.Collections.Generic;
using POS.BusinessEntities;
using POS.DataObjects;

namespace POS.BusinessComponents
{
    public class BCEntidad
    {
        #region Declarations

        private readonly DOEntidad doEntity;
        private const string TempUser = "tempUser"; // TODO: Use the corresponding value
        private const int TempEmpresa = 1;         // TODO: Use the corresponding value

        #endregion

        #region Constructors

        public BCEntidad(TipoEntidad entity): this(new DOEntidad(entity)){}

        public BCEntidad(DOEntidad doEntity)
        {
            this.doEntity = doEntity;
        }

        #endregion

        #region Methods: Public

        public virtual List<BEEntidad> GetList(string filtro)
        {
            return doEntity.GetList(TempEmpresa, filtro);
        }

        public virtual BEEntidad GetItemByName(string name)
        {
            var lista = doEntity.GetList(TempEmpresa, name);
            if (lista.Count == 1)
                return lista[0];

            return null;
        }

        public virtual void Delete(int id)
        {
            doEntity.Delete(id, TempUser);
        }

        public virtual void Save(BEEntidad entidad)
        {
            doEntity.Save(entidad, TempEmpresa, TempUser);
        }

        #endregion
        
    }
}
